home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ptv3n5.zip / STRWRITE.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-01  |  6KB  |  140 lines

  1. { An Improved TTerminal.StrWrite() Method }
  2. {etc.}
  3. {================================================================
  4.  Define an interior view for the window...
  5. ----------------------------------------------------------------}
  6.   PInterior = ^TInterior;
  7.   TInterior = OBJECT(TTerminal)
  8.     TheText : PTextBuf;         { TextBuf for Terminal "writes" }
  9.     MaxWide : Integer;              { Maximum TScroller.Limit.X }
  10.     { Other application-specific variables }
  11. {----------------------------------------------------------------
  12.  TInterior Methods...
  13. ----------------------------------------------------------------}
  14.     CONSTRUCTOR Init(VAR Bounds: TRect;
  15.                      AHScrollBar, AVScrollBar: PScrollBar;
  16.                      ABufSize : Word);
  17.     DESTRUCTOR Done; VIRTUAL;
  18.     PROCEDURE StrWrite(VAR S : TextBuf; Count : Byte); VIRTUAL;
  19.     PROCEDURE HandleEvent(VAR Event : TEvent); VIRTUAL;
  20.     { Other application-specific methods }
  21.   END;
  22. {etc.}
  23. {****************************************************************
  24.               T I n t e r i o r   M e t h o d s
  25. ----------------------------------------------------------------}
  26. CONSTRUCTOR TInterior. Init(VAR Bounds: TRect;
  27.                            AHScrollBar, AVScrollBar: PScrollBar;
  28.                            ABufSize : Word);
  29. {----------------------------------------------------------------
  30.   Initializes the TInterior object.
  31. ----------------------------------------------------------------}
  32. BEGIN
  33. {----------------------------------------------------------------
  34.   Call the parent object's initialization logic.
  35.   Initialize key parameters...
  36. ----------------------------------------------------------------}
  37.   TTerminal.Init(Bounds,AHScrollBar,AVScrollBar,ABufSize);
  38.   TheText  := New(PTextBuf);
  39.   MaxWide  := SizeOf(TextBuf); {------------------------- NOTE! }
  40.   { Other application-specific initialization }
  41. END;
  42. {===============================================================}
  43. DESTRUCTOR TInterior.Done;
  44. {----------------------------------------------------------------
  45.   Cleans up TInterior data...
  46. ----------------------------------------------------------------}
  47. BEGIN
  48.   { Other application-specific clean-up }
  49.   Dispose(TheText);
  50.   TTerminal.Done;
  51. END;
  52. {===============================================================}
  53. PROCEDURE TInterior.StrWrite(VAR S : TextBuf; Count : Byte);
  54. {----------------------------------------------------------------
  55.  Replacement for TTerminal.StrWrite().  DOES NOT call CaldWidth;
  56.  used MaxWide for SetLimit call.
  57.  ----------------------------------------------------------------}
  58. VAR
  59.   I,J,LimitY: Word;
  60.  
  61. BEGIN
  62. {----------------------------------------------------------------
  63.  Ensure that the "Count" is valid.
  64. ----------------------------------------------------------------}
  65.   IF (Count <= 0) THEN Exit;             { Exit for a bad count }
  66.   IF (Count >= BufSize) THEN Count := BufSize - 1;
  67.   LimitY := Limit.Y;                    { Local copy of Limit.Y }
  68.   J      := 0;
  69. {----------------------------------------------------------------
  70.  Process each charater in "S"
  71. ----------------------------------------------------------------}
  72.   FOR I := 0 TO (Count - 1) DO BEGIN 
  73.     IF (S[I] = ^M) THEN Dec(Count)    { "Lose" carraige returns }
  74.     ELSE BEGIN
  75.       IF (S[I] = ^J) THEN Inc(LimitY);  { LF means another line }
  76.       S[J] := S[I];
  77.       Inc(J);
  78.     END;
  79.   END; {------------------------------ FOR I := 0 TO LvCnt... }
  80. {----------------------------------------------------------------
  81.  If necessary, purge oldest line(s) to fit in "Count" characters
  82. ----------------------------------------------------------------}
  83.   WHILE (NOT CanInsert(Count)) DO BEGIN
  84.     QueBack := NextLine(QueBack);
  85.     Dec(LimitY);
  86.   END;
  87. {----------------------------------------------------------------
  88.  If necessary, handle wraparound to beginning of buffer
  89. ----------------------------------------------------------------}
  90.   IF ((QueFront + Count) >= BufSize) THEN BEGIN
  91.     I := BufSize - QueFront;
  92.     Move(S,Buffer^[QueFront],I);
  93.     Move(S[I],Buffer^,(Count - I));
  94.     QueFront := Count - I;
  95.   END
  96. {----------------------------------------------------------------
  97.  Otherwise, move the full "S" contents into the buffer at QueFront.
  98. ----------------------------------------------------------------}
  99.   ELSE BEGIN
  100.     Move(S,Buffer^[QueFront],Count);
  101.     QueFront := QueFront + Count;
  102.   END;
  103. {----------------------------------------------------------------
  104.  Set the scroller's horizontal and vertical limits...
  105.  NOTE: The replaces "SetLimit(CalcWidth,LvLimY);"
  106. ----------------------------------------------------------------}
  107.   SetLimit(MaxWide,LimitY);
  108. {----------------------------------------------------------------
  109.  - Scroll to the new location, using the local "Y" limit value.
  110.  - Calculate the new cursor position, and set the cursor there.
  111.  - Redraw the screen before exiting.
  112. ----------------------------------------------------------------}
  113.   ScrollTo(0,(LimitY + 1));
  114.   I := PrevLines(QueFront,1);
  115.   IF (I <= QueFront) THEN I := QueFront - I
  116.   ELSE I := BufSize - (I - QueFront);
  117.   SetCursor(I,(LimitY - Delta.Y) - 1);
  118.   DrawView;
  119. END;
  120. {===============================================================}
  121. PROCEDURE TInterior.HandleEvent(VAR Event : TEvent);
  122. {----------------------------------------------------------------
  123.   Handles keyboard input to the "Interior."
  124. ----------------------------------------------------------------}
  125. BEGIN
  126. {----------------------------------------------------------------
  127.  Let the parent object (TTerminal) handle the standard events.
  128. ----------------------------------------------------------------}
  129.   TTerminal.HandleEvent(Event);
  130. {----------------------------------------------------------------
  131.  If a key was pressed,...
  132. ----------------------------------------------------------------}
  133.   IF (Event.What = evKeyDown) THEN BEGIN
  134.     CASE Event.KeyCode OF
  135.     { Application-specific processing }
  136.     END; {--------------------------- CASE Event.KeyCode OF ... }
  137.   END; {------------------------ IF (Event.What = evKeyDown)... }
  138. END;
  139.  
  140.